// columns.ts

import DictTag, { DictValueEnum } from "@/components/DictTag";
import { QuestionCircleOutlined } from "@ant-design/icons";
import { ProColumns } from "@ant-design/pro-table";
import { Divider, Image, MenuProps, Popconfirm, Space, Typography } from "antd";

// 定义所有列的工厂函数
export const createTableColumns = (
	statusOptions: DictValueEnum,
	handleColumnEditor: (record: API.Tenant.TenantVo) => void,
	handleColumnRemove: (record: API.Tenant.TenantVo) => void,
	handleColumnAsync: (record: API.Tenant.TenantVo) => void,
	handleColumnDetails: (record: API.Tenant.TenantVo) => void
): ProColumns<API.Tenant.TenantVo>[] => {
	return [
		{
			title: "LOGO",
			dataIndex: "logo",
			hideInSearch: true,
			render: (_: any, record: any) => {
				return <Image width={30} src={record?.logo} placeholder="" />;
			}
		},
		{
			title: "企业名称",
			dataIndex: "companyName",
			valueType: "text",
			ellipsis: true
		},
		{
			title: "租户编号",
			dataIndex: "tenantId",
			valueType: "text",
			ellipsis: true,
			search: false
		},
		{
			title: "联系人",
			dataIndex: "contactUserName",
			valueType: "text",
			ellipsis: true
		},
		{
			title: "联系电话",
			dataIndex: "contactPhone",
			valueType: "text",
			ellipsis: true
		},
		{
			title: "社会信用代码",
			dataIndex: "licenseNumber",
			valueType: "text",
			ellipsis: true
		},
		{
			title: "过期时间",
			key: "expireTime1",
			dataIndex: "expireTime",
			valueType: "date",
			sorter: true,
			hideInSearch: true
		},
		{
			title: "过期时间",
			dataIndex: "expireTime",
			valueType: "dateRange",
			hideInTable: true,
			width: "100%",
			search: {
				transform: (value: any) => {
					return {
						startTime: value[0],
						endTime: value[1]
					};
				}
			}
		},
		{
			title: "状态",
			dataIndex: "status",
			valueType: "select",
			sorter: true,
			valueEnum: statusOptions,
			render: (_: any, record: any) => {
				return <DictTag enums={statusOptions} type="badge" value={record.status} />;
			}
		},
		{
			title: "操作",
			dataIndex: "option",
			valueType: "option",
			fixed: "right",
			render: (_, record: any) => {
				return (
					<>
						<Space size={1} split={<Divider type="vertical" />}>
							<Typography.Link
								key="details"
								onClick={() => {
									handleColumnDetails(record);
								}}
							>
								详情
							</Typography.Link>
							{record?.id !== 1 && (
								<Typography.Link
									key="edit"
									onClick={() => {
										handleColumnEditor(record);
									}}
								>
									编辑
								</Typography.Link>
							)}

							{record?.id !== 1 && (
								<Typography.Link
									key="sync"
									onClick={() => {
										handleColumnAsync(record);
									}}
								>
									同步
								</Typography.Link>
							)}

							{record.id !== 1 && (
								<Popconfirm
									placement="bottomRight"
									title={"警告"}
									description={() => {
										return (
											<div style={{ width: 260 }}>
												您确定要删除租户名为“{record?.companyName}”吗？
												<br />
												执行此操作后，相关数据将被永久删除，无法恢复。
											</div>
										);
									}}
									onConfirm={() => {
										handleColumnRemove(record);
									}}
									icon={<QuestionCircleOutlined style={{ color: "red" }} />}
									okText="确认"
									cancelText="取消"
								>
									<Typography.Link type="danger" key="batchRemove">
										删除
									</Typography.Link>
								</Popconfirm>
							)}
						</Space>
					</>
				);
			}
		}
	];
};
const listOperItem: MenuProps["items"] = [
	{
		label: "重置密码",
		key: "restPassword"
	},
	{
		label: "授权角色",
		key: "authRole"
	}
];
export const proTableCardProps = {
	bodyStyle: {
		paddingInline: 0,
		paddingBlock: 0
	}
};

export const pagination = {
	showQuickJumper: true,
	showSizeChanger: true
};

export const formTitle = ["添加用户", "编辑用户"];
